<?php

class controller_content extends controller_theme
{

	public function __construct()
	{
		parent::__construct();
	}

	public function frontpage()
	{
		$id = get('id', 0, 'int');
		$content = bone::get_table('content');
		$content->load_frontpage();
		$content->hit();

		$template = bone::get_template('content.detail');
		$template->set_title($content->title);
		$template->set('content', $content);
		$template->set_data($this->get_data());
		$template->display();
	}

	public function all()
	{
		$category_id = get('category_id', -1, 'int');

		$model = bone::get_model('content');
		$template = bone::get_template('content.all');
		$template->set_title('文章列表');

		$limit = 50;
		$pagination = $template->get_pagination();
		$pagination->set_limit( $limit );
		$pagination->set_page(get('page', 1, 'int'));
		$pagination->set_total($model->get_content_sum($category_id));
		$pagination->set_url('./?controller=content&task=listing');

		$content_list = $model->get_content_list($category_id, $pagination->get_offset(), $limit);
		$category_list = $model->get_category_tree_list();

		$template->set('category_id', $category_id);
		$template->set('content_list', $content_list);
		$template->set('category_list', $category_list);

		$template->set_data($this->get_data());
		$template->display();
	}

	public function listing()
	{
		$category_id = get('category_id', 0, 'int');

		if(!$category_id) exit('缺少{category_id}参数');

		$table = bone::get_table('content_category');
		$table->load($category_id);

		$model = bone::get_model('content');
		$template = bone::get_template('content.listing');
		$template->set_title($table->name);

		$limit = 50;
		$pagination = $template->get_pagination();
		$pagination->set_limit( $limit );
		$pagination->set_page(get('page', 1, 'int'));
		$pagination->set_total($model->get_content_sum($category_id));
		$pagination->set_url('./?controller=content&task=listing');

		$content_list = $model->get_content_list($category_id, $pagination->get_offset(), $limit);
		$template->set('category_id', $category_id);
		$template->set('content_list', $content_list);

		$template->set_data($this->get_data());
		$template->display();
	}

	public function detail()
	{
		$id = get('id', 0, 'int');
		$content = bone::get_table('content');
		$content->load($id);
		$content->hit();

		$template = bone::get_template('content.detail');
		$template->set_title($content->title);
		$template->set_meta_keyword( $content->meta_keywords );
		$template->set_meta_description( $content->meta_description );
		$template->set('content', $content);
		$template->set_data($this->get_data());
		$template->display();
	}

}
?>